package com.soft.line.controller;

import com.soft.line.service.StatisticsService;
import com.soft.line.util.exception.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(description = "统计接口")
@Slf4j
@RequestMapping("/statistics")
@RestController
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @ApiOperation(value = "统计证书", notes = "统计证书")
    @PostMapping("/certificates")
    public CommonResult statisticsForCertificate(@RequestBody Map<String,Object> map){
        return CommonResult.success(statisticsService.statisticsForCertificate(map));
    }

    @ApiOperation(value = "年部门合同统计", notes = "年部门合同统计")
    @PostMapping("/contracts/countNumGroupByDepThisYear")
    public CommonResult countNumGroupByDepThisYear(@RequestBody Map<String,Object> map){
        return CommonResult.success(statisticsService.countNumGroupByDepThisYear(map));
    }

    @ApiOperation(value = "根据部门分组查询历年数量", notes = "根据部门分组查询历年数量")
    @PostMapping("/contracts/countDepGroupByYear")
    public CommonResult countDepGroupByYear(@RequestBody Map<String,Object> map){
        return CommonResult.success(statisticsService.countDepGroupByYear(map));
    }

    @ApiOperation(value = "合同类型统计", notes = "合同类型统计")
    @PostMapping("/contracts/countNumByTypeYear")
    public CommonResult countNumByTypeYear(){
        return CommonResult.success(statisticsService.countNumByTypeYear());
    }

    @ApiOperation(value = "合同总金额排行榜", notes = "合同总金额排行榜")
    @PostMapping("/contracts/amountRanking")
    public CommonResult amountRankingForContract(){
        return CommonResult.success(statisticsService.amountRankingForContract());
    }


    @ApiOperation(value = "部门合同排行榜", notes = "部门合同排行榜")
    @PostMapping("/contracts/depRanking")
    public CommonResult depRankingForContract(){
        return CommonResult.success(statisticsService.depRankingForContract());
    }


    @ApiOperation(value = "今年证书类型排行", notes = "今年证书类型排行")
    @PostMapping("/certificates/certTypeRankThisYear")
    public CommonResult certTypeRankThisYear(){
        return CommonResult.success(statisticsService.certTypeRankThisYear());
    }

    @ApiOperation(value = "根据年份来统计合同数量", notes = "根据年份来统计合同数量")
    @PostMapping("/contracts/sumContractByYear")
    public CommonResult sumContractByYear(@RequestBody Map<String,Object> map){
        return CommonResult.success(statisticsService.sumContractByYear(map));
    }

    @ApiOperation(value = "根据年份来统计合同性质", notes = "根据年份来统计合同性质")
    @PostMapping("/contracts/sumContractNatureByYear")
    public CommonResult sumContractNatureByYear(@RequestBody Map<String,Object> map){
        return CommonResult.success(statisticsService.sumContractNatureByYear(map));
    }

    @ApiOperation(value = "根据部门年份来统计合同性质", notes = "根据部门年份来统计合同性质")
    @PostMapping("/contracts/sumContractNatureByYearAndDep")
    public CommonResult sumContractNatureByYearAndDep(@RequestBody Map<String,Object> map){
        return CommonResult.success(statisticsService.sumContractNatureByYearAndDep(map));
    }

    @ApiOperation(value = "根据部门统计合同个数", notes = "根据部门统计合同个数")
    @PostMapping("/contracts/countNumGroupByDep")
    public CommonResult countNumGroupByDep(){
        return CommonResult.success(statisticsService.countNumGroupByDep());
    }
}
